﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsModel.BusinessObjects;
using WindowsFormsView;

namespace WindowsFormsPresenter.RestaurantMenuCategory
{
    public class RestaurantMenuCategoryPresenter : Presenter<IRestaurantMenuCategoryView>
    {
        public RestaurantMenuCategoryPresenter(IRestaurantMenuCategoryView view)
            : base(view)
        {
        }

        public void Display(string menuCategoryId)
        {
            if (menuCategoryId == null) return;

            var restaurantMenuCategory = Model.GetRestaurantMenuCategory(menuCategoryId);

            View.MenuCategoryID = restaurantMenuCategory.MenuCategoryID;
            View.MenuCategoryCode = restaurantMenuCategory.MenuCategoryCode;
            View.MenuCategoryName = restaurantMenuCategory.MenuCategoryName;
            View.RestaurantID = restaurantMenuCategory.RestaurantID;
            View.IsParent = restaurantMenuCategory.IsParent;
            View.ParentID = restaurantMenuCategory.ParentID;
            View.Description = restaurantMenuCategory.Description;
            View.IsActive = restaurantMenuCategory.IsActive;
        }

        public int Save()
        {
            var restaurantMenuCategory = new RestaurantMenuCategoryModel
            {
                MenuCategoryID = View.MenuCategoryID,
                MenuCategoryCode = View.MenuCategoryCode,
                MenuCategoryName = View.MenuCategoryName,
                RestaurantID = View.RestaurantID,
                IsParent = View.IsParent,
                ParentID = View.ParentID,
                Description = View.Description,
                IsActive = View.IsActive
            };

            if (View.MenuCategoryID == null)
                return Model.AddRestaurantMenuCategory(restaurantMenuCategory);
            else
                return Model.UpdateRestaurantMenuCategory(restaurantMenuCategory);
        }

        public int Delete(string menuCategoryId)
        {
            return Model.DeleteRestaurantMenuCategory(menuCategoryId);
        }
    }
}
